<template>
  <div class="right">
    <el-dropdown @command="userDropdown">
      <div class="header-user">
        <span>{{$store.state.admin.nickname}}<i class="el-icon-arrow-down el-icon--right"></i></span>
      </div>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item
          command="refresh"
          v-if="$store.state.admin.id == 1"
        >
          <span class="red">刷新缓存</span>
        </el-dropdown-item>
        <el-dropdown-item command="chpw">修改密码</el-dropdown-item>
        <el-dropdown-item command="out">退出登录</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>

<script>
import { refreshCache, logout } from "@/api";
import Cpw from "@/view/admin/chpw"
export default {
  methods: {
    //退出
    userDropdown(type) {
      switch (type) {
        case "refresh":
          this.$confirm("确定刷新缓存？", () => {
            refreshCache(() => {
              // location.reload();
            });
          });
          break;
        case "out":
          this.$confirm("确定退出登录？", () => {
            logout(
              () => {
                this.$router.replace({ name: "login" });
              }
            );
          });
          break;
        case "chpw":
        this.$uDialog({
          title:"修改密码",
          component:Cpw,
          data:{},
          close:()=>{
            
          }
        })
          // this.$router.push({ name: "chpw" });
          break;
      }
    }
  }
};
</script>
